package com.lost.sos;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.lost.sos.cfg.Configs;

import java.text.SimpleDateFormat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        // /data/data/com.lost.sos/files/configs/config.xml

        if (Configs.Config.getBool(getContentResolver(), "is_first_login", true)) {
            Configs.Config.putBool(getContentResolver(), "is_first_login", false);
            Configs.Config.putString(getContentResolver(), "name", "monkey");
            Configs.Config.putInt(getContentResolver(), "age", 30);
            Configs.Config.putBool(getContentResolver(), "male", true);
            Configs.Config.putLong(getContentResolver(), "lastLogin", System.currentTimeMillis());
        }

        getTextView(R.id.name).setText(Configs.Config.getString(getContentResolver(), "name"));
        getTextView(R.id.age).setText(String.valueOf(Configs.Config.getInt(getContentResolver(), "age", -1)));
        getTextView(R.id.male).setText(Configs.Config.getBool(getContentResolver(), "male", true) ? "male" : "female");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        getTextView(R.id.lastLogin).setText(simpleDateFormat.format(Configs.Config.getLong(getContentResolver(), "lastLogin", -1)));
    }

    private TextView getTextView(int id) {
        return (TextView) findViewById(id);
    }

}
